<template>
  <div id='headbox'>
    <span :class='classname'
      @click="isopen"></span>
    <div class='headbox-info'>
      <div
        class='el-icon-user-solid'>
      </div>
      <div class='info-name'>
        欢迎您,{{username}}
      </div>
      <div class='line'></div>
      <div class='exit'
        @click='exitbtn'>
        <i
          class='el-icon-circle-close'>
        </i>
        <div>
          退出
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Cookie from '../cookies/cookies'
export default {
  name: 'headbox',
  data() {
    return {
      show: false,
      classname: 'el-icon-s-fold',
      username: '',
    }
  },
  mounted() {
    this.$store.state.username = Cookie.getCookie().username
    this.username = this.$store.state.username
  },
  methods: {
    exitbtn() {
      Cookie.setCookie('password', 0, 0)
      Cookie.setCookie('userID', 0, 0)
      Cookie.setCookie('username', 0, 0)
      sessionStorage.setItem('index', 0)
      this.$router.replace({ path: '/login' })
    },
    isopen() {
      this.show = !this.show
      if (this.show) {
        this.classname = 'el-icon-s-unfold'
      } else {
        this.classname = 'el-icon-s-fold'
      }
      this.$emitter.emit('sendinfo', this.show)
    },
  },
}
</script>

<style lang='less'>
#headbox {
  width: 100%;
  height: 60px;
  background: url(/image/navbar_bg_1.137fb7f1.png);
  background-size: cover;
  position: relative;
  overflow: hidden;
  .exit {
    margin-right: 20px;
    cursor: pointer;

    .el-icon-circle-close::before {
      font-size: 20px;
      overflow: hidden;
      vertical-align: middle;
      margin-right: 4px;
    }
  }
  .el-icon-s-fold:before,
  .el-icon-s-unfold:before {
    position: absolute;
    left: 15px;
    display: inline-block;
    color: #fff;
    font-size: 30px;
    cursor: pointer;
  }
  .headbox-info {
    position: absolute;
    height: 100%;
    top: 0;
    right: 22px;
    color: #bbbbbb;
    font-size: 14px;
    font-weight: 540;
    line-height: 60px;
    div {
      display: inline-block;
      vertical-align: middle;
    }
    .el-icon-user-solid:before {
      display: inline-block;
      background-color: #fff;
      border-radius: 50%;
      overflow: hidden;
      box-shadow: 0px 0px 5px #cbcbcb;
      color: #4667d8;
      font-size: 26px;
      vertical-align: middle;
      margin-right: 10px;
    }
    .line {
      display: inline-block;
      width: 2px;
      height: 17px;
      background-color: #dadadb;
      margin: 0 18px;
    }
  }
}
</style>